<?php
$sub_menu = "230400";
include_once("./_common.php");

auth_check($auth[$sub_menu], "r");

$colspan = 6;

$g4['title'] = "멤버쉽 설정";
include_once("$g4[admin_path]/admin.head.php");
?>

<?=subtitle($g4[title])?>

<table width=100% cellpadding=0 cellspacing=1>
<colgroup width=100>
<colgroup width=''>
<colgroup width=100>
<colgroup width=100>
<colgroup width=100>
<colgroup width=100>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td> 고유번호 </td>
    <td> 멤버쉽 </td>
    <td> 사용 </td>
    <td> 누적 </td>
    <td> 현재 </td>
    <td> <a href="mw.membership.form.php"><img src="<?=$g4[admin_path]?>/img/icon_insert.gif" border="0"></a> </td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>

<?
$t_acc = $t_now = 0;

$sql = "select * from $mw_cash[membership_table] order by ms_id desc";
$qry = sql_query($sql);
for ($i=0; $row=sql_fetch_array($qry); $i++)
{
    $row2 = sql_fetch("select count(*) as cnt from $mw_cash[membership_log_table] where ms_id = '$row[ms_id]'");
    $row3 = sql_fetch("select count(*) as cnt from $mw_cash[membership_log_table] where ms_id = '$row[ms_id]' and '$g4[time_ymdhis]' between ml_sdate and ml_edate");

    $t_acc += $row2[cnt];
    $t_now += $row3[cnt];

    $list = $i%2;
?>

<tr class='list<?=$list?> col1 ht center'>
    <td> <?=$row[ms_id]?> </td>
    <td> <?=$row[ms_name]?> </td>
    <td> <? if ($row[ms_status]) echo "√"; ?> </td>
    <td> <a href="javascript:membership_log(<?=$row[ms_id]?>, 0, 0)"><?=number_format($row2[cnt])?> 명</a> </td>
    <td> <a href="javascript:membership_log(<?=$row[ms_id]?>, 0, 1)"><?=number_format($row3[cnt])?> 명</a> </td>
    <td>
        <a href="mw.membership.form.php?ms_id=<?=$row[ms_id]?>&w=u"><img src="<?=$g4[admin_path]?>/img/icon_modify.gif" border="0"></a>
        <a href="javascript:del('mw.membership.update.php?w=d&ms_id=<?=$row[ms_id]?>');"><img src="<?=$g4[admin_path]?>/img/icon_delete.gif" border="0"></a>
    </td>
</tr>

<? } ?>

<?
if (!$i)
    echo "<tr> <td style='height:100px; text-align:center;' colspan='$colspan' class='b'> 자료가 없습니다. </td></tr>";
?>

<tr><td colspan='<?=$colspan?>' class='line2'></td></tr>
<tr class='bgcol1 bold col1 ht center'>
    <td style="font-weight:bold;"> 합 계 </td>
    <td>&nbsp;</td>
    <td>&nbsp;</td>
    <td> <a href="javascript:membership_log(0, 0, 0)"><?=number_format($t_acc)?> 명</a> </td>
    <td> <a href="javascript:membership_log(0, 0, 1)"><?=number_format($t_now)?> 명</a> </td>
    <td> &nbsp; </td>
</tr>
<tr><td colspan='<?=$colspan?>' class='line1'></td></tr>
</table>

<script type="text/javascript">
function membership_log(ms_id, mi_day, acc) {
    location.href = "mw.membership.log.php?ms_id=" + ms_id + "&mi_day=" + mi_day + "&acc=" + acc;
}
</script>

<?
include_once ("$g4[admin_path]/admin.tail.php");
